<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_restaurants'.DS.'tables');

class RestaurantsViewSingle extends JView
{	
	function display($tpl = null)
	{
		global $mainframe;
		$params =& $mainframe->getParams();
		
		$id = (int) JRequest::getVar('id', 0);
		
		$review =& JTable::getInstance('review', 'Table');
		$review->load($id);
		
		if ($review->published == 0) {
			JError::raiseError(404, 'The review you requested is not available.' );
		}
		
		if ($review->smoking == 1) {
			$smoking = 'Yes';
		} else {
			$smoking = 'No';
		}
		
		$date = JHTML::Date($review->review_date);
		
		$backlink = JRoute::_('index.php?option=com_restaurants');
		$emaillink = JRoute::_('index.php?option=com_restaurants&view=email&id=' . $id);
		
		$user =& JFactory::getUser();
		
		$comments =& $this->get('Comments');
		
		jimport('joomla.filesystem.file');

		$download = '';

		if (JFile::exists(JPATH_COMPONENT . DS . 'audio' . DS . $id . '.mp3')) {
			$download = JURI::base() . 'components/com_restaurants/audio/' . $id . '.mp3';
		}
		
		$this->assign('display_comments', $params->get('display_comments', '1'));
		$this->assignRef('review', $review);
		$this->assignRef('smoking', $smoking);
		$this->assignRef('date', $date);
		$this->assignRef('backlink', $backlink);
		$this->assignRef('emaillink', $emaillink);
		$this->assignRef('name', $user->name);
		$this->assignRef('comments', $comments);
		$this->assign('download', $download);
		
		parent::display($tpl);
	}
}
